<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" :hidden="disabled">新增</a-button>
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpCarMaintenanceDetails:delete')"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="key"
        :columns="defColumns"
        :dataSource="dataSource"
        :pagination="false"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <!-- <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template> -->

        <span slot="action" slot-scope="text, record">
          <a-button
            class="ruleButton"
            :ghost="true"
            type="primary"
            icon="edit"
            :hidden="disabled"
            @click="handleEdit(record)"
            :disabled="isDisabledAuth('erpCarMaintenanceDetails:edit')"
          />
          <a-divider type="vertical"/>
          <a-popconfirm title="确定删除吗?" @confirm="() => handleclose(record.key)">
            <a-button
              class="ruleButton"
              :ghost="true"
              type="primary"
              icon="delete"
              :hidden="disabled"
              :disabled="isDisabledAuth('erpCarMaintenanceDetails:delete')"/>
          </a-popconfirm>
        </span>
        <span slot="modelAndViewRender" slot-scope="text, record">
          {{ text }}
          <!-- <j-ellipsis :value="text" :length="10"/> -->
        </span>
      </a-table>
    </div>

    <erp-car-maintenance-details-modal ref="modalForm" @dataOne="dataOne"></erp-car-maintenance-details-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ErpCarMaintenanceDetailsModal from './modules/ErpCarMaintenanceDetailsModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import { getAction } from '@/api/manage'

export default {
    name: 'ErpCarMaintenanceDetailsList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpCarMaintenanceDetailsModal,
    },
    data () {
      return {
        description: '维修明细管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'故障',
            align:"center",
            dataIndex: 'fault',
            ellipsis: true,
            scopedSlots: { customRender: 'modelAndViewRender' },
          },
          {
            title:'维修项目',
            align:"center",
            ellipsis: true,
            dataIndex: 'maintenanceItems',
            scopedSlots: { customRender: 'modelAndViewRender' },
          },
          {
            title:'维修金额（元）',
            align:"center",
            dataIndex: 'maintenanceMoney',
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark',
            ellipsis: true,
            scopedSlots: { customRender: 'modelAndViewRender' },
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: "/api/erp/erpcarmaintenancedetails/erpCarMaintenanceDetails/list",
          delete: "/api/erp/erpcarmaintenancedetails/erpCarMaintenanceDetails/delete",
          deleteBatch: "/api/erp/erpcarmaintenancedetails/erpCarMaintenanceDetails/deleteBatch",
          exportXlsUrl: "/api/erp/erpcarmaintenancedetails/erpCarMaintenanceDetails/exportXls",
          importExcelUrl: "/api/erp/erpcarmaintenancedetails/erpCarMaintenanceDetails/importExcel",
        },
        dictOptions:{},
        superFieldList:[],
        disableMixinCreated: true,
      }
    },
    props: {
      disabled: {
        type: Boolean,
        default: false
      }
    },
    created() {
      this.getSuperFieldList();
      if(this.disabled){
        this.defColumns.pop()
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      handleclose: function (key) {
        if(this.dataSource.length == 1) {
          this.dataSource = []
          return
        }
        this.dataSource.splice(key,1);
        this.dataSource.forEach((item, index) => {
          item.key = index
        })
      },
      dataOne(data, flag) {
        if(flag) {
          this.dataSource.push(data)
          this.dataSource.forEach((item, index) => {
            item.key = index
          })
        } else {
          this.dataSource.splice(data.key,1,data);
        }
      },
      submitForm() {
        return this.dataSource
      },
      initDictConfig(id){
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        var params = {
          maintenanceId: id,
          pageNo: 1,
          pageSize: 100,
          column: 'createTime',
          order: 'desc'
        }
        this.loading = true
        getAction(this.url.list, params).then(res => {
          if (res.success) {
            this.dataSource = res.result.records || res.result
            this.dataSource.forEach((item, index) => {
              item.key = index
            })
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'fault',text:'故障',dictCode:''})
        fieldList.push({type:'string',value:'maintenanceItems',text:'维修项目',dictCode:''})
        fieldList.push({type:'string',value:'maintenanceMoney',text:'维修金额（元）',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>